﻿@page
@model Pages.PageA
@using static System.Convert

@section Subcategories {
    <partial name="_Subcategories" />
}

@section Tabs {
    <span class="dialog-tab@(Model.Condition ? " selected" : "")"><span class="link" data-url="/Category/PageA">Sub cat A</span></span>
    <span class="dialog-tab"><span class="link" data-url="/Category/PageB/@Model.Value1/@Model.Value2">Sub cat B</span></span>
    <span class="dialog-tab"><span class="link" data-url="/Category/PageC/@((int)Model.Value3)">Sub cat C</span></span>
    <span class="dialog-tab@(!Model.Condition ? " selected" : "")"><span class="link" data-url="/Category/PageD/@((int)Model.Value3)">Sub cat D</span></span>
}

@switch (Model.Value)
{
    case 0:
        <h1>@Model.Name Type A</h1>
        break;
    case 1:
        <h1>@Model.Name Type B</h1>
        break;
    case 2:
        <h1>@Model.Name Type C</h1>
        break;
}


<h3 style="clear:both;">Something Something</h3>
<div>
    <table class="generic small oddeven middle center">
        <tr>
            <th style="width: 24px;"></th>
            <th>Something</th>
            <th style="width: 270px;">Something Something</th>
            @if (Model.Value3 != 0)
            {
                <th style="width: 70px;" class="dull right">Something</th>
            }
            <th style="width: 130px;"></th>
        </tr>
        @{
            foreach (var data in Model.Data1)
            {
                <tr>
                    <td class="left">@data.Icon</td>
                    <td class="left">@data.Name</td>
                    <td style="text-align:center">@data.Html</td>
                    @if (Model.Value3 != 0)
                    {
                        <td class="dull right">
                            @(new TimeSpan(0, 0, (int)data.Seconds)) <br />
                            (@data.PerHour.ToString("N2") p/h)
                        </td>
                    }
                    <td>
                        <form asp-page-handler="Make">
                            <input type="hidden" name="Id" value="@((int)Model.Value3)" />
                            <input type="hidden" name="ResType" value="@data.Id" />
                            <input type="text" name="Quantity" style="width: 35px; font-size: 11px; text-align: left;" placeholder="@data.Max.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)" />
                            <a href="#" class="max">max</a>
                            <button class="small">Make</button>
                        </form>
                    </td>
                </tr>
            }
        }
    </table>
</div>

<h3 style="clear:both;">Something something something</h3>
<div>
@{
    if (Model.Data2.Count > 0)
    {
        <table class="oddeven" style="font-size: 11px;">
            <tr>
                <th style="width:20px"></th>
                <th class="left">SomethingA</th>
                <th style="width: 80px;">SomethingB</th>
                <th style="width: 60px">SomethingC</th>
                <th>SomethingD</th>
                <th style="width: 60px">SomethingE</th>
                <th style="width: 90px;">SomethingF</th>
                <th style="width: 56px;"></th>
            </tr>

            @foreach (var data in Model.Data2)
            {
                var StartDate = data.StartDate;
                var CompleteDate = data.CompleteDate;

                <tr>
                    <td>@data.Icon</td>
                    <td class="left">@data.Name</td>
                    <td>@data.Value</td>
                    <td class="center">@StartDate.ToString("dd MMM HH:mm:ss")</td>
                    @{
                        float percentage = 100f;

                        var totalTime = CompleteDate.Subtract(StartDate).TotalMilliseconds;
                        if (totalTime > 1000)
                        {
                            percentage = 100f * (float)DateTimeOffset.UtcNow.Subtract(StartDate).TotalMilliseconds / (float)totalTime;
                        }

                        percentage = MathF.Min(100f, MathF.Max(0f, percentage));

                        var startDate = ToInt64(StartDate.Subtract(DateTime.UnixEpoch).Ticks / (double)10000);
                        var endDate = ToInt64(CompleteDate.Subtract(DateTime.UnixEpoch).Ticks / (double)10000);
                    }
                    <td>
                        <div class="progBar">
                            <div class="progProgress" data-start="@startDate" data-end="@endDate" style="width: @(percentage.ToString("N0"))%;"></div>
                        </div>
                    </td>
                    <td class="center">@CompleteDate.ToString("dd MMM HH:mm:ss")</td>
                    <td>
                        <span class="progTime" data-start="@startDate" data-end="@endDate">@(CompleteDate.Subtract(DateTime.UtcNow).ToString())</span>
                    </td>
                    <td>
                        <form method="post" asp-page-handler="Cancel">
                            <input type="hidden" name="id" value="@data.Id" />
                            <button class="small">Cancel</button>
                        </form>
                    </td>
                </tr>
            }
        </table>
    }
    else
    {
        <span>Something @Model.Name something something something something.</span>
    }

}
</div>